﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tester.DL645.Core;

namespace Tester.DL645.Instructions
{
    /// <summary>
    /// 
    /// </summary>
    public class OnInstruction: AbstractInstruction
    {
        public string Password { get; set; }
        public string Auth { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="address"></param>
        /// <param name="password"></param>
        /// <param name="auth"></param>
        public OnInstruction(string address, string password = "0000", string auth = "02") : base(address, 0X1C)
        {
            this.Password = password;
            this.Auth = auth;
        }
        /// <summary>
        /// 
        /// </summary>
        private void ApplyPassword(List<byte> buffer)
        {
            // buffer.AddRange(PasswordField.Reverse(this.Password));

            buffer.AddRange(new byte[] { 0x33, 0x33, 0x33 });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="password"></param>
        private void ApplyAuth(List<byte> buffer)
        {
            //var authByte = (byte)(byte.Parse(this.Auth, System.Globalization.NumberStyles.HexNumber) + 0X33);
            buffer.Add(0x35);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="buffer"></param>
        private void ApplyOperator(List<byte> buffer)
        {
            buffer.AddRange(Constants.OperatorCharacters);
        }
        protected override void ApplyData(List<byte> buffer)
        {
            buffer.Add(0X10);
            //4
            this.ApplyAuth(buffer);
            this.ApplyPassword(buffer);
            //4
            this.ApplyOperator(buffer);

            buffer.AddRange(new byte[] {
                   0X4F,0X33,0X8C,0X8C
                 ,0X56,0X48,0X3B,0X58});
        }

       // public override byte[] Bytes => new byte[] { 0X68, 0X99, 0X00, 0X12, 0X04, 0X25, 0X41, 0X68, 0X1C, 0X10, 0X35, 0X33, 0X33, 0X33, 0XB7, 0X72, 0X38, 0X9C, 0X4F, 0X33, 0X8C, 0X8C, 0X56, 0X48, 0X3B, 0X58, 0XA7, 0X16 };

    }
}
